package com.xw.service.xw.drug;

import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Service;

import com.xw.dao.DaoSupport;
import com.xw.entity.Page;
import com.xw.entity.system.Role;
import com.xw.entity.xw.Datas;
import com.xw.entity.xw.Drug;
import com.xw.entity.xw.Feedback;
import com.xw.entity.xw.Kc;
import com.xw.entity.xw.Patient;
import com.xw.util.PageData;

/**
 * 类名称: DrugService
 * 类描述: 药品业务类
 *
 */
@Service("drugService")
public class DrugService {
	
	@Resource(name = "sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;
	@Resource(name = "daoSupport")
	private DaoSupport daoSupport;
	
	/**
	 * 获取药品资料列表
	 * @param pd
	 * @return
	 * @throws Exception 
	 */
	public List<PageData> getList(Page page) throws Exception {
		List<PageData> list=null;
		list=(List<PageData>) daoSupport.findForList("DrugMapper.getList_listPage", page);
		return list;
	}
	
	/**
	 * 新增药品资料
	 * @param drug
	 * @throws Exception 
	 */
	public void add(Drug drug) throws Exception {
		daoSupport.save("DrugMapper.add",drug);
	}
	
	
	/**
	 * 新增库存为0
	 * @param drug
	 * @throws Exception 
	 */
	public void addkc(Kc kc) throws Exception {
		daoSupport.save("DrugMapper.addkc",kc);
	}
	
	
	/**
	 * 药品类型
	 * @param 
	 * @throws Exception 
	 */
	public List<Datas> listYplx() throws Exception {
		return (List<Datas>) daoSupport.findForList("DrugMapper.listYplx", null);
	}
	
	
	/**
	 * 药品单位
	 * @param 
	 * @throws Exception 
	 */
	public List<Datas> listYpdw() throws Exception {
		return (List<Datas>) daoSupport.findForList("DrugMapper.listYpdw", null);
	}
	
	
	/**
	 * 根据ID获取一条信息 
	 * @param pd
	 * @return
	 * @throws Exception
	 */
	public Drug getOne(PageData pd) throws Exception {
		Drug drug = null;
		drug = (Drug) daoSupport.findForObject("DrugMapper.getOne", pd);
		return drug;
	}
	
	
	
	/**
	 * 修改药品资料信息
	 * @param Feedback
	 * @throws Exception 
	 */
	public void edit(Drug drug) throws Exception {
		daoSupport.update("DrugMapper.editDrug", drug);
	}
	
	
	
	/**
	 * 删除药品资料
	 * @param pd
	 * @throws Exception 
	 */
	public void delete(PageData pd) throws Exception {
		daoSupport.delete("DrugMapper.deleteById", pd);
	}
	
	
	/**
	 * 批量删除药品资料
	 */
	public void deleteAll(String[] USER_IDS) throws Exception {
		daoSupport.delete("DrugMapper.deleteAll", USER_IDS);
	}
	
	
	/**
	 * 判断药品编号是否存在
	 * @param pd
	 * @return
	 * @throws Exception
	 */
	public Drug findYp(PageData pd) throws Exception {
		Drug drug = null;
		drug = (Drug) daoSupport.findForObject("DrugMapper.findYp", pd);
		return drug;
	}
	
}
